import { fakeAccountLogin } from '../services/login';

import { forEach } from 'lodash';
import { routerRedux } from 'dva/router';

export default {
  namespace: 'login',

  state: {
    status: undefined,
  },

  effects: {
    *login({ payload }, { call, put }) {
      //debugger;
      const data = yield call(fakeAccountLogin, payload);
      
      if (data != null) {
        yield put({
          type: 'changeLoginStatus',
          payload: data,
        });

        //登录成功
        localStorage.setItem('loginFlag',data.token);
        yield put(routerRedux.push('/'));
      }
    },
    *logout(_, { put }) {
      localStorage.setItem('loginFlag',null);
      yield put(routerRedux.push('/user/login'));
    },
  },

  reducers: {

  },
};
